package com.ehotting.mqbd.core.service;

import com.ehotting.mqbd.api.bean.MQDataAble;
import com.ehotting.mqbd.core.logger.MQSendLogger;
import com.ehotting.mqbd.core.mq.MessageProducer;
import com.ehotting.mqbd.core.service.mq.MQBaseService;
import com.ehotting.mqbd.core.service.mq.MQServiceAble;
import com.ehotting.mqbd.core.service.storage.RedisMqStorage;
import com.ehotting.mqbd.core.sync.MqSyncFutureMapHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.FutureTask;


public class MQService extends MQBaseService implements MQServiceAble {


    @Autowired
    private RedisMqStorage redisMqStorage;

    public MQService(MessageProducer messageProducer, MqSyncFutureMapHelper<MQDataAble> mqSyncFutureMapHelper, MQSendLogger logger) {
        super(messageProducer, mqSyncFutureMapHelper, logger);
    }

    @Override
    public void request(MQDataAble data) {
        handleStorage(data);
        super.request(data);
    }

    @Override
    public MQDataAble request(MQDataAble data, boolean sync) {
        handleStorage(data);
        return super.request(data,sync);
    }

    @Override
    public MQDataAble request(MQDataAble data, long timeout) {
        handleStorage(data);
        return super.request(data, timeout);
    }

    @Override
    public FutureTask<MQDataAble> requestFuture(MQDataAble data,long timeout){
        handleStorage(data);
        return super.requestFuture(data, timeout);
    }


    private void handleStorage(MQDataAble data) {
        redisMqStorage.handlePut(data);;
    }


}
